﻿ 
// Generated File 
// Generated: 13-6-2010 14:57:41
namespace PersonLookup.ViewModel
{
	public partial class Persons : System.ComponentModel.INotifyPropertyChanged
	{
		#region Properties
		
		#region Collection Property
		
		private PersonLookup.ViewModel.PersonCollection _collection;
		public PersonLookup.ViewModel.PersonCollection Collection
		{
			get
			{
				return _collection;
			}
			set
			{
				if (_collection != value)
				{
					_collection = value;
					OnPropertyChanged("Collection");
				}
			}
		}
		
		#endregion
		#region NewPerson Property
		
		private PersonLookup.ViewModel.Person _newPerson;
		public PersonLookup.ViewModel.Person NewPerson
		{
			get
			{
				return _newPerson;
			}
			set
			{
				if (_newPerson != value)
				{
					_newPerson = value;
					OnPropertyChanged("NewPerson");
				}
			}
		}
		
		#endregion
		#region SelectedPerson Property
		
		private PersonLookup.ViewModel.Person _selectedPerson;
		public PersonLookup.ViewModel.Person SelectedPerson
		{
			get
			{
				return _selectedPerson;
			}
			set
			{
				if (_selectedPerson != value)
				{
					_selectedPerson = value;
					OnPropertyChanged("SelectedPerson");
				}
			}
		}
		
		#endregion
		#region EditPerson Property
		
		private PersonLookup.ViewModel.Person _editPerson;
		public PersonLookup.ViewModel.Person EditPerson
		{
			get
			{
				return _editPerson;
			}
			set
			{
				if (_editPerson != value)
				{
					_editPerson = value;
					OnPropertyChanged("EditPerson");
				}
			}
		}
		
		#endregion

		#endregion	
		
		public Persons()
		{
			GetAllCommand = new global::MVVM.ActionCommand(GetAllCommand_Execute);
			AddPersonCommand = new global::MVVM.ActionCommand(AddPersonCommand_Execute);
			EditPersonCommand = new global::MVVM.ActionCommand(EditPersonCommand_Execute);
			DeletePersonCommand = new global::MVVM.ActionCommand(DeletePersonCommand_Execute);
			UpdateCommand = new global::MVVM.ActionCommand(UpdateCommand_Execute);
			ConstructorExecuting();
		}
		
		partial void ConstructorExecuting();
		#region Commands
		
		#region AddPersonCommandCommand Command
		
		public System.Windows.Input.ICommand AddPersonCommand
		{
			get;
			private set;
		}
		
		private void AddPersonCommand_Execute(object parameter)
		{
			AddPersonCommandExecute(parameter);
		}
		
		partial void AddPersonCommandExecute(object parameter);
				
		#endregion
		
		#region EditPersonCommandCommand Command
		
		public System.Windows.Input.ICommand EditPersonCommand
		{
			get;
			private set;
		}
		
		private void EditPersonCommand_Execute(object parameter)
		{
			EditPersonCommandExecute(parameter);
		}
		
		partial void EditPersonCommandExecute(object parameter);
				
		#endregion
		
		#region DeletePersonCommandCommand Command
		
		public System.Windows.Input.ICommand DeletePersonCommand
		{
			get;
			private set;
		}
		
		private void DeletePersonCommand_Execute(object parameter)
		{
			DeletePersonCommandExecute(parameter);
		}
		
		partial void DeletePersonCommandExecute(object parameter);
				
		#endregion
		
		#region UpdateCommandCommand Command
		
		public System.Windows.Input.ICommand UpdateCommand
		{
			get;
			private set;
		}
		
		private void UpdateCommand_Execute(object parameter)
		{
			UpdateCommandExecute(parameter);
		}
		
		partial void UpdateCommandExecute(object parameter);
				
		#endregion
		
		#region GetAllCommand Command
		
		public System.Windows.Input.ICommand GetAllCommand
		{
			get;
			private set;
		}
		
		public void GetAllCommand_Execute(object parameter)
		{
			var viewModelProvider = new PersonLookup.ViewModel.Providers.PersonsProvider();
			viewModelProvider.GetAllCompleted += viewModelProvider_GetAllCompleted;
			viewModelProvider.GetAllAsync(this);
		}
		
		partial void GetAllCompleted(PersonLookup.ViewModel.PersonCollection persons, System.Exception error, object userState);
		
		public void viewModelProvider_GetAllCompleted(object sender, PersonLookup.ViewModel.Providers.PersonsProvider.GetAllCompletedEventArgs e)
		{
			GetAllCompleted(e.Result, e.Error, e.UserState);
		}
		
		#endregion
		
		#endregion
		
	
		#region INotifyPropertyChanged Implementation
		
		public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

		protected void OnPropertyChanged(string propertyName)
		{
			System.ComponentModel.PropertyChangedEventHandler p = PropertyChanged;
			if (p != null)
			{
				p(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
			}
		}
		
		#endregion
	}
}

			
namespace PersonLookup.ViewModel.Providers
{
	public partial class PersonsProvider
	{
		#region GetAll Implementation
		
		public class GetAllCompletedEventArgs : System.EventArgs
		{
			public PersonLookup.ViewModel.PersonCollection Result
			{
				get;
				private set;
			}
			
			public System.Exception Error
			{
				get;
				private set;
			}
			
			public object UserState
			{
				get;
				private set;
			}
			
			public GetAllCompletedEventArgs(PersonLookup.ViewModel.PersonCollection result, System.Exception error, object userState)
			{
				Result = result;
				Error = error;
				UserState = userState;
			}
		}
		
		public event System.EventHandler<GetAllCompletedEventArgs> GetAllCompleted;
	
		public void GetAllAsync(object userState = null)
		{
			var modelProvider = new PersonLookup.PersonServiceReference.PersonServiceClient();
			modelProvider.GetPersonsCompleted += PersonsProvider_GetPersonsCompleted;
			modelProvider.GetPersonsAsync(userState);
		}
		
		public void PersonsProvider_GetPersonsCompleted(object sender, PersonLookup.PersonServiceReference.GetPersonsCompletedEventArgs e)
		{
			System.EventHandler<GetAllCompletedEventArgs> ev = GetAllCompleted;
			if(ev != null)
			{
		
				var result = PersonLookup.ViewModel.PersonCollection.FromModel(e.Result);
		
				ev(this, new GetAllCompletedEventArgs(result, e.Error, e.UserState));
			}
		}
		
		#endregion
		
	}
}

